

Function logme($logSpaces, $nachricht, $logNewLine, $logTarget)
{
    $jetzt = Get-Date -format yyyy.MM.dd_HH.mm.ss
    Write-Host $jetzt
    
    if ($doLogging)
    {
        $strSpaces = New-Object String(' ',$logSpaces)
        Write-Host $strSpaces  -NoNewline;
  

        if ($logTarget -eq "console" -or $logTarget -eq "both") 
        {
            if ($logNewLine) 
                    { Write-Host $nachricht }
                else 
                    { Write-Host $nachricht -NoNewline }
        }

        if ($logTarget -eq "file" -or $logTarget -eq "both")
        {
            if ($logNewLine) 
                {  [IO.File]::AppendAllText("N:\Abteilungsdaten\5539\Fleck\EnterpriseSearch\dev\x-deployment\TESTS\test.log",$jetzt + " " + $strSpaces + $nachricht + [Environment]::NewLine) 
                }
            else
                {  [IO.File]::AppendAllText("N:\Abteilungsdaten\5539\Fleck\EnterpriseSearch\dev\x-deployment\TESTS\test.log",$jetzt + " " + $strSpaces + $nachricht) }

        }
    }
    
}

Clear-Host;

$doLogging = $true
log 0 "hallo"  $true "file"
log 0 "2ndline" $true "file"
log 5 "both destinations 1" $true "both"
log 7 "both destinations 2" $true "both"
log 10 "console 1" $true "console"
